package com.nineclock.document.controller;



import com.nineclock.common.entity.Result;
import com.nineclock.document.dto.DocFileDto;
import com.nineclock.document.dto.DocFolderDto;

import com.nineclock.document.service.DocFolderService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import com.nineclock.api.document.DocumentControllerApi;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.document.dto.DocFileDto;
import com.nineclock.document.dto.DocFileHistoryDto;
import com.nineclock.document.service.DocumentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping
public class DocumentController implements DocumentControllerApi {



    //注入对象
    @Autowired
    DocFolderService docFolderService;

    @PostMapping("/insertFolder")
    public Result createFolder(@RequestBody DocFolderDto docFolderDto){

        docFolderService.createFolder(docFolderDto);

        return Result.success();
    }
    @Autowired
    DocumentService documentService;

    @Override
    @GetMapping("/pagingFile")
    public Result<PageResult<DocFileDto>> QueryDocumentList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                                            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                            @RequestParam(value = "keyword") String keyword) {
        PageResult<DocFileDto> fileDtoPage = documentService.QueryDocumentList(page,pageSize,keyword);
        return Result.success(fileDtoPage);
    }

    @Override
    @PutMapping("/{fileId}/{status}")
    public Result update(@PathVariable("fileId") Long fileId, @PathVariable("status") Short status) {
        documentService.update(fileId,status);
        return Result.success();
    }

    @Override
    @GetMapping("/history/{fileId}")
    public Result<List<DocFileHistoryDto>> QueryHistoryOperation(@PathVariable("fileId") Long fileId) {
        List<DocFileHistoryDto> fileHistoryDtoList = documentService.QueryHistoryOperation(fileId);
        return Result.success(fileHistoryDtoList);
    }


}
